<?php

if(stristr($_SERVER['PHP_SELF'],".inc.php")) { 
	header("Location:index.php"); 
	exit; 
}

if($_POST['lang']) {
	if($_COOKIE['flip_lang']) { setcookie("flip_lang", '', (time()-2592000)); } 
	setcookie("flip_lang", $_POST['lang'], time()+31536000); 
	header("Location: ?");
	exit;
} elseif($_COOKIE['flip_lang']) { 	
	unset($CONFIG['lang']);
	$CONFIG['lang'] = $_COOKIE['flip_lang'];
	$i18n = "./inc/lang/lang_" . strtolower($CONFIG['lang']) . ".inc.php"; 
	if(file_exists($i18n)) { 
		require($i18n); 
	} else { 
		require("./inc/lang/lang_en.inc.php");  
	}
} else { 
	$i18n = "./inc/lang/lang_" . strtolower($CONFIG['lang']) . ".php"; 
		if(file_exists($i18n)) { 
			require($i18n); 
		} else { 
			require("./inc/lang/lang_en.inc.php");  
		}
}

$langdir = dir("./inc/lang/");
while($u = $langdir->read()) {
	if(strstr($u,"lang_") && strstr($u,".php")) {
		$langs[] = $u; 
	} 
}
?>